package de.jmda.mview.proj;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.DefaultTreeCellRenderer;

import de.jmda.mview.DesktopPane;
import de.jmda.util.gui.awt.graphics.IconProvider;

public class DiagramsTreeCellEditor
//		extends JTextField
//		implements TreeCellEditor
    extends DefaultTreeCellEditor
{
	public DiagramsTreeCellEditor(
			JTree tree, DefaultTreeCellRenderer treeCellRenderer)
  {
	  super(tree, treeCellRenderer);
  }

	@Override
  public Component getTreeCellEditorComponent(
  		JTree tree, Object value, boolean isSelected, boolean expanded,
  		boolean leaf, int row)
  {
		Component result =
				super.getTreeCellEditorComponent(
						tree, value, isSelected, expanded, leaf, row);
		
		if (value instanceof DefaultMutableTreeNode)
		{
			DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
			
			Object userObject = treeNode.getUserObject();
			
			if (userObject == null)
			{
				renderer.setText("unexpected null user object");
			}
			else if (userObject instanceof DiagramGroup)
			{
				editingIcon = IconProvider.getIconPackage();
//				renderer.setIcon(IconProvider.getIconPackage());
//				renderer.setText(((DiagramGroup) userObject).name);
			}
			else if (userObject instanceof DesktopPane.JAXBModel)
			{
				editingIcon = IconProvider.getIconDocumentSmall();
//				renderer.setIcon(IconProvider.getIconDocumentSmall());
//				renderer.setText(((DesktopPane.JAXBModel) userObject).name);
			}
			else
			{
				renderer.setText(
						"unexpected user object type " + userObject.getClass().getName());
			}
		}
		else
		{
			renderer.setText("unexpected value type " + value.getClass().getName());
		}
		
		return result;
  }
}